{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-04-07T09:57:43.362739Z",
     "start_time": "2025-04-07T09:57:43.354755Z"
    }
   },
   "source": [
    "import pandas as pd\n",
    "from matplotlib import pyplot as plt"
   ],
   "outputs": [],
   "execution_count": 73
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-04-07T09:57:43.392661Z",
     "start_time": "2025-04-07T09:57:43.369722Z"
    }
   },
   "cell_type": "code",
   "source": [
    "file_path = \"02500005.csv\"\n",
    "# 读取原始数据\n",
    "raw_data = pd.read_csv(file_path)\n",
    "\n",
    "print(len(raw_data))"
   ],
   "id": "823be4bb7bc0e3a9",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "13089\n"
     ]
    }
   ],
   "execution_count": 74
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-04-07T09:57:43.454302Z",
     "start_time": "2025-04-07T09:57:43.425005Z"
    }
   },
   "cell_type": "code",
   "source": [
    "raw_data['data_time'] = pd.to_datetime(raw_data['data_time'], format='%Y-%m-%d %H:%M:%S')\n",
    "\n",
    "# 提取月份和小时值，并创建新列 h 和 m\n",
    "raw_data['h'] = raw_data['data_time'].dt.hour\n",
    "raw_data['m'] = raw_data['data_time'].dt.month\n",
    "raw_data[\"mm\"] = raw_data['data_time'].dt.minute\n",
    "\n",
    "mm_data = raw_data[\"mm\"].values\n",
    "\n",
    "data_time = raw_data['data_time'].values\n",
    "ep_zone_data = raw_data['ep_zone'].values\n",
    "# p_data = raw_data['p'].values"
   ],
   "id": "861134ec23a51da8",
   "outputs": [],
   "execution_count": 75
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-04-07T09:57:43.500178Z",
     "start_time": "2025-04-07T09:57:43.486216Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import ipywidgets as widgets\n",
    "from IPython.display import display, clear_output\n"
   ],
   "id": "ad22ef1490dd00d5",
   "outputs": [],
   "execution_count": 76
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-04-07T09:57:43.829729Z",
     "start_time": "2025-04-07T09:57:43.534088Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 获取时间范围\n",
    "min_time = data_time.min()\n",
    "max_time = data_time.max()\n",
    "\n",
    "# 初始化时间滑动条\n",
    "start_time_slider = widgets.SelectionSlider(\n",
    "    options=data_time,\n",
    "    value=min_time,\n",
    "    description='Start Time:',\n",
    "    continuous_update=False,\n",
    "    layout=widgets.Layout(width='800px')  # 设置滑动条宽度为800像素\n",
    ")\n",
    "\n",
    "end_time_slider = widgets.SelectionSlider(\n",
    "    options=data_time,\n",
    "    value=max_time,\n",
    "    description='End Time:',\n",
    "    continuous_update=False,\n",
    "    layout=widgets.Layout(width='800px')  # 设置滑动条宽度为800像素\n",
    ")\n",
    "\n",
    "# 更新图形的函数\n",
    "def update_plot(start_time, end_time):\n",
    "    # 清除之前的输出\n",
    "    clear_output(wait=True)\n",
    "\n",
    "    # 创建图形对象\n",
    "    fig, ax = plt.subplots(figsize=(12, 6))\n",
    "\n",
    "    # 获取时间范围内的索引\n",
    "    start_index = raw_data[raw_data['data_time'] == start_time].index[0]\n",
    "    end_index = raw_data[raw_data['data_time'] == end_time].index[0]\n",
    "\n",
    "    # 绘制 ep_zone 的折线图\n",
    "    ax.plot(data_time[start_index:end_index], ep_zone_data[start_index:end_index], label='ep_zone', marker='.', linestyle='-', color='blue')\n",
    "\n",
    "    # 绘制 p_data 的折线图\n",
    "    # ax.plot(data_time[start_index:end_index], p_data[start_index:end_index], label='p_data', marker='x', linestyle='--', color='red')\n",
    "\n",
    "    # 添加图例\n",
    "    ax.legend()\n",
    "\n",
    "    # 添加标题和坐标轴标签\n",
    "    ax.set_title('ep_zone and p_data over Time')\n",
    "    ax.set_xlabel('Time')\n",
    "    ax.set_ylabel('Value')\n",
    "\n",
    "    # 设置时间轴的格式\n",
    "    fig.autofmt_xdate()  # 自动旋转日期标签，避免重叠\n",
    "    ax.grid(True)  # 添加网格线\n",
    "\n",
    "    # 限制 y 轴的最大值\n",
    "    ax.set_ylim(bottom=0, top=1000)  # 设置 y 轴的范围，可以根据需要调整 top 的值\n",
    "\n",
    "    # 显示图形\n",
    "    plt.show()\n",
    "\n",
    "# 将时间滑动条的值绑定到更新函数\n",
    "widgets.interactive(update_plot, start_time=start_time_slider, end_time=end_time_slider)"
   ],
   "id": "bd3141241fbc467d",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "interactive(children=(SelectionSlider(continuous_update=False, description='Start Time:', layout=Layout(width=…"
      ],
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "d1dbe91b7b8d4f3793c96f531498141b"
      }
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 77
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-04-07T09:57:43.875606Z",
     "start_time": "2025-04-07T09:57:43.862642Z"
    }
   },
   "cell_type": "code",
   "source": "",
   "id": "a2b7d5317ba0ac28",
   "outputs": [],
   "execution_count": null
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
